def main():
    s =input("请输入字符串：")
    if len(s) <= 0 or len(s)> 255:
        print("输入的字符串不合法！")
    letter(s)
def letter(s):
    s1 = list(filter(lambda char: char.isalpha(), s))
    print("去除非英文字符后密文：{}".format(s1))
    s2 = revese(s1)
    print("反转后密文：{}".format(s2))
    s3 = enCode(s2)
    print("加密后密文：{}".format(s3))

def revese(s2):
    new_string = []
    index = len(s2)
    while index:
        index -= 1
        new_string += s2[index]
    return new_string
def enCode(s3):
    k = 4
    str_list = s3
    str_list_encry = str_list
    i = 0
    while i < len(str_list):
        if ord(str_list[i]) < 123-k:
            str_list_encry[i] = chr(ord(str_list[i]) + k)
        else:
            str_list_encry[i] = chr(ord(str_list[i]) + k - 26)
        i = i+1
    return str_list_encry      
main()
